package asteroids.model.programs.expression;

import java.util.ArrayList;

import asteroids.model.programs.type.*;

public abstract class Function extends DoubleExpression {

	private E e;
	
	public Function(int line, int column, E e) {
		super(line, column);
		this.e = e;
	}

	@Override
	public abstract DoubleType getValue();
	
	public E getExpression(){
		return e;
	}

	@Override
	public ArrayList<VariableExpression> getVariables(){
		return e.getVariables();
	}
	
	public String typecheck(){
		String eTypeCheck = getExpression().typecheck();
		if(!eTypeCheck.equals(""))
			return eTypeCheck;
		if(getExpression().getValue() == null)		
			return "Typecast error at line " + getLine() + ", column " + getColumn() + ".\n";
		if(getExpression().getValue().getClass() != DoubleType.class)
			return "Typecast error at line " + getLine() + ", column " + getColumn() + ".\n";
		return "";
	}
}
